﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SmoothControls
{
	public class DoubleBufferControl : Control
	{
		protected override void OnPaint( PaintEventArgs e )
		{
			using ( var currentRender = new Bitmap( this.Width, this.Height ) )
			using ( var currentRenderGraphics = Graphics.FromImage( currentRender ) )
			{
				var args = new PaintEventArgs( currentRenderGraphics, e.ClipRectangle );
				OnPaintBuffer( args );
				e.Graphics.DrawImage( currentRender, 0, 0 );
			}
			base.OnPaint( e );
		}

		protected virtual void OnPaintBuffer( PaintEventArgs args )
		{
		}
	}
}

